package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

/**
 * 调用Person类中所有被注解@AutoRunMethod标注的方法
 */
public class Test4 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method[] methods = cls.getDeclaredMethods();
        for(Method method : methods) {
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark) {
                System.out.println("调用方法:"+method.getName()+"()");
                method.invoke(obj);
            } else {
                System.out.println(method.getName()+"()没有被标注");
            }
        }
    }
}
